﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace PloobsEngine.SceneControl
{
    public sealed class TextureRenderer
    {
        private VertexPositionTexture[] verts;         
        private VertexDeclaration VertexDeclaration { get; set; }
        private GraphicsDevice myDevice;

        public void LoadContent(EngineStuff engine) 
        {
            myDevice = EngineStuff.GraphicsDevice;

            verts = new[] {
                new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)), 
                new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)), 
                new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1)), 
                new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0))
            }; 
            VertexDeclaration = new VertexDeclaration(myDevice, VertexPositionTexture.VertexElements); 
            
        }        

        public void DrawQuad(Effect effect)
        {            
            effect.Begin();            
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            { 
                pass.Begin(); 
                myDevice.VertexDeclaration = VertexDeclaration; 
                myDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, verts, 0, 2); 
                pass.End(); 
            } 
            effect.End();            
            
        }   

    
    }
}
